package net.oschina.app.adapter.my;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;

import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.Active;
import net.oschina.app.databinding.MsgItemMeBinding;

import java.util.List;

/**
 * Created by YL on 2017/4/5.
 */
public class ActiveMeAdapter extends BaseRecyclerViewAdapter{
    /**
     * Created by YL on 2017/4/2.
     */
    private List<Active> flist;

    public ActiveMeAdapter(List<Active> active) {
        this.flist = active;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.msg_item_me, parent, false);
        ActiveViewHolder holder = new ActiveViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        ActiveViewHolder viewHolder = (ActiveViewHolder) holder;
        Active active = flist.get(position);
        MsgItemMeBinding binding = DataBindingUtil.bind(holder.itemView);
        binding.setActive(active);
        Spanned spanned = Html.fromHtml(active.getMessage());
        binding.setMessage(spanned);
        binding.setObjecttype(active.getObjectType()+"");
        binding.setImageUrl(active.getPortrait());
    }

    @Override
    public int getItemCount() {
        return flist.size();
    }

    public class ActiveViewHolder extends RecyclerView.ViewHolder {

        public ActiveViewHolder(View itemView) {
            super(itemView);
        }
    }

}
